<template>
  <!-- 真正登陆页面 -->
  <div>
    <div class="big-box">
      <img src="../assets/登录页.jpg" alt="" />
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit"
            >立即登陆</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { GoLogin } from "../request/api";
export default {
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
      let username = values["用户名"];
      let password = values["密码"];
      GoLogin({
        username,
        password
      }).then(res => {
        console.log(res);
        if (res.errCode == "0") {
          this.$toast.success("登陆成功!");
          localStorage.setItem("token", res.data);
          setTimeout(() => {
            this.$router.push("/home");
          }, 1500);
        } else {
          console.log(res.message);
        }
      });
    }
  }
};
</script>
 
<style lang = "less" scoped>
.big-box {
  width: 100%;
  position: relative;
  img {
    width: 100%;
  }
}
.van-form {
  position: absolute;
  bottom: 30%;
  left: 25%;
}
.van-field {
  padding-left: 2em;
  color: #000;
  margin-top: 0.133333rem;
  border-radius: 0.533333rem;
  background-color: #ffcd33;
  border: 2px solid #000;
  height: 0.4333rem;
}
.van-button {
  width: 1.733333rem;
  position: absolute;
  bottom: -90%;
}
</style>